﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cocos2d;

namespace CampaignWP7
{
    public class CampaignWP7Scene : CCLayer
    {
        /// <summary>
        ///  Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
        /// </summary>
        /// 
        CCMenu pMenu;

        
        //CCLayer layerMenu;
       // static CCLayer layerStart;
        public override bool init()
        {
            CCDirector.sharedDirector().deviceOrientation = ccDeviceOrientation.CCDeviceOrientationPortrait;//.CCDeviceOrientationLandscapeLeft;
            
            //////////////////////////////
            // 1. super init first
            if (!base.init())
            {
                return false;
            }

            this.m_bIsTouchEnabled = true;
            /////////////////////////////
            // 2. add a menu item with "X" image, which is clicked to quit the program
            //    you may modify it.

            // add a "close" icon to exit the progress. it's an autorelease object
            CCMenuItemImage bStart = CCMenuItemImage.itemFromNormalImage(
                                                "Menu/StartNormal",
                                                "Menu/StartSelect",
                                                this,
                                                new SEL_MenuHandler(menuStartCallback));
            CCMenuItemImage bOpenXLiveCenter = CCMenuItemImage.itemFromNormalImage(
                                                "Menu/StartNormal",
                                                "Menu/StartSelect",
                                                this,
                                                new SEL_MenuHandler(menuOpenXLiveCallback));
            CCMenuItemImage bAboutUs = CCMenuItemImage.itemFromNormalImage(
                                                "Menu/AboutUsNormal",
                                                "Menu/AboutUsSelect",
                                                this,
                                                new SEL_MenuHandler(menuAboutUsCallback));
            

            // create menu, it's an autorelease object
            pMenu = CCMenu.menuWithItems(bStart, bOpenXLiveCenter, bAboutUs);

            pMenu.alignItemsVerticallyWithPadding(30);
            pMenu.position = CCDirector.sharedDirector().convertToUI(new CCPoint(CCDirector.sharedDirector().getWinSize().width / 2, CCDirector.sharedDirector().getWinSize().height / 2));
            this.addChild(pMenu, 1);

            ///////////////////////////////
            //// 3. add your codes below...

            //// add a label shows "Hello World"
            //// create and initialize a label
            //CCLabelTTF pLabel = CCLabelTTF.labelWithString("Hello World", "Arial", 24);
            //// ask director the window size
            //CCSize size = CCDirector.sharedDirector().getWinSize();

            //// position the label on the center of the screen
            //pLabel.position = new CCPoint(size.width / 2, size.height - 50);

            //// add the label as a child to this layer
            //this.addChild(pLabel, 1);

            //// add "HelloWorld" splash screen"
            //CCSprite pSprite = CCSprite.spriteWithFile("AboutUsNormal");

            //// position the sprite on the center of the screen
            //pSprite.position = new CCPoint(size.width / 2, size.height / 2);

            //// add the sprite as a child to this layer
            //this.addChild(pSprite, 0);
            //

            //


            return true;
        }

        /// <summary>
        /// there's no 'id' in cpp, so we recommand to return the exactly class pointer
        /// </summary>
        public static CCScene scene()
        {
            
            CCScene scene = CCScene.node();

            CCLayer layerMenu = CampaignWP7Scene.node();

            //layerStart = CampaignWP7Scene.node();
           // layerStart.visible = false;
           
            // add layer as a child to scene
            //scene.addChild(layerStart);
           scene.addChild(layerMenu);

            // return the scene
            return scene;
        }

        public static new CCLayer node()
        {
            CampaignWP7Scene ret = new CampaignWP7Scene();
            if (ret.init())
            {
                return ret;
            }
            else
            {
                ret = null;
            }

            return ret;
        }

        /// <summary>
        /// a selector callback
        /// </summary>
        /// <param name="pSender"></param>
        /// 
       private void menuStartCallback(CCObject pSender)
        {

            CCDirector.sharedDirector().pushScene(GameLayer.scene());

            GameStatusManager.instance.SetStatus(GameStatus.GAMESTATUS_PLAY);

           // layerMenu.visible = true;
            //layerStart.visible = true;
            //CCDirector.sharedDirector().end();
            //CCApplication.sharedApplication().Game.Exit();
        }
     
       private void menuAboutUsCallback(CCObject pSender)
        {

            CCDirector.sharedDirector().pushScene( AboutUs.scene());

            GameStatusManager.instance.SetStatus(GameStatus.GAMESTATUS_ABOUT);
            
        }

       private void menuOpenXLiveCallback(CCObject pSender)
       {
           SocialManager.instance.SelectedOpenXLive();

           GameStatusManager.instance.SetStatus(GameStatus.GAMESTATUS_SOCIAL);
       }

    }
}
